import React,{FC} from 'react';
import {HashRouter, Switch, Route, Redirect} from "react-router-dom";

/*用import引入路由时有时会报错，暂未解决，改用const方式获取*/
import login from '../pages/login';
const index=require('../pages/index');
const Main=require('../pages/main');
const SubjectNavigation=require('../pages/SubjectNavigation');

const routes: any[] = [
    {
        path: "/login",
        component: login,
    },
    {
        path:'index',
        component:index,
        routes:[
            {
                path: "/index/main",
                component: Main,
            },
            {
                path: "/index/subjectNavigation",
                component: SubjectNavigation,
            },
        ]
    }
];

const RouteConfig: FC<any> = () => {
    return (
        <HashRouter>
            <Switch>
                {routes.map((route, i) => (
                    <Route
                        key={i}
                        path={route.path}
                        render={props => (
                            <route.component {...props} routes={route.routes} />
                        )}
                    />
                ))}
                {/* 设置默认路由 */}
                <Redirect path="/" exact={true} to="/index/main" />
            </Switch>
        </HashRouter>
    )
}

export default RouteConfig
